namespace cs5643.rigidbody
{
    
    using System;

    /** 
     * Catch-all utilities (feel free to add on). 
     * 
     * @author Doug James, January 2007
     */
    public class Utils
    {




        /**
         * 
         * @param pad Pre-padding char.
         */
        public static String getPaddedNumber(int number, int length, String pad)
        {
            return getPaddedString("" + number, length, pad, true);
        }

        /**
         * @param prePad Pre-pads if true, else post pads.
         */
        public static String getPaddedString(String s, int length, String pad, bool prePad)
        {
            if (pad.Length != 1) throw new ArgumentException("pad must be a single character.");
            String result = s;
            result.Trim();
            if (result.Length > length)
                throw new Exception
                ("input string " + s + " is already more than length=" + length);

            int nPad = (length - result.Length);
            for (int k = 0; k < nPad; k++)
            {
                //Console.Out.WriteLine("nPad="+nPad+", result="+result+", result.Length()="+result.Length());
                if (prePad)
                    result = pad + result;
                else
                    result = result + pad;
            }

            return result;
        }
    }
}